package org.feng.sensitive;

import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;

import java.nio.charset.StandardCharsets;

/**
 * Base64 转码的加解密实现
 *
 * @version v1.0
 * @author: fengjinsong
 * @date: 2023年08月25日 20时43分
 */
@Component
public class Base64Sensitive extends AbstractSensitive {

    public static final String SENSITIVE_TYPE_CODE = "base64";

    @Override
    public String encrypt(String text) {
        return Base64Utils.encodeToString(text.getBytes(StandardCharsets.UTF_8));
    }

    @Override
    public String decrypt(String ciphertext) {
        return new String(Base64Utils.decodeFromString(ciphertext), StandardCharsets.UTF_8);
    }

    @Override
    public String getSensitiveType() {
        return SENSITIVE_TYPE_CODE;
    }
}
